package com.family.business.custom.ajax;


import java.util.List;

import javax.annotation.Resource;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.family.business.custom.dto.CustomDto;
import com.family.business.custom.service.CustomIService;
import com.opensymphony.xwork2.ActionSupport;

@Namespace("/customAjax")
@ParentPackage("json-default")
@Scope(value="prototype")
public class CustomAjaxAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = -9198369075202771330L;
	
	@Resource(name="customService")
	private CustomIService customService;

	@JSONField
	private String result;
	
	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	private Long id;
	private String customName;
	
	
	
	 //进入页面  
    public String execute(){  
        return SUCCESS;  
    } 

    //AJAX
    @Action(value="get",results={
    		@Result(name="json",type="json")
    })
	public String parent(){
    	CustomDto dto = this.customService.getCustom(this.id);
    	
    	CustomJson json = new CustomJson();
    	json.setBirthday(dto.getBirthday());
    	json.setCusName(dto.getCusName());
    	json.setCusSex(dto.getCusSex());
    	json.setId(dto.getId());
    	json.setIsLive(dto.getIsLive());
    	json.setLiveCity(dto.getLiveCity());
    	json.setNowAdrr(dto.getNowAdrr());
    	json.setOthName(dto.getOthName());
    	json.setParentAddr(dto.getParentAddr());
    	
    	this.result = JSONObject.toJSONString(json);
		System.out.println(this.result);
		return "json";
	}
    
    @Action(value="listparent",results={@Result(name="listparent",type="json")})
    public String listParent() throws Exception{
    	List<CustomJson> list = this.customService.listCustomByName(this.customName);
    	this.result = JSONObject.toJSONString(list);
    	return "listparent";
    }
    
    public String getCustomName() {
		return customName;
	}

	public void setCustomName(String customName) {
		this.customName = customName;
	}

	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}

	
}
